﻿using System.Diagnostics;
using System.Globalization;
using System.Windows.Data;

namespace BHan.Util
{

    public class StringToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) { return null; }
            if (value is string strValue)
            {
                return bool.TryParse(strValue, out var result) && result;
            }
            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string stringValue)
            {
                if (value.Equals("正常")) {  return false; }
                if (value.Equals("禁用")) {  return true; }
            }
            return null;
        }
    }

}
